package com.gitee.hermer.engine.jars.core.app.domain;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.Map;

import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.SynthesizedAnnotation;
import org.springframework.data.annotation.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gitee.hermer.engine.jars.core.domain.ToStringObject;

public class EngineAppMethodBean extends ToStringObject {
	
	private Class<?> beanClass;
	private String beanName;
	@Transient
	@JsonIgnore
	private transient Object beanObject;
	private String methodName;
	private Type[] parameterTypes;
	private Class<?>[] parameterClass;
	private Class<?> returnType;
	private String version;
	private String describe;
	@Transient
	@JsonIgnore
	private transient Method method;
	@Transient
	@JsonIgnore
	private transient ClassLoader classLoader;
	private Class<? extends Annotation> annotationClass;
	private Map<String,Object> annotationAttributes;
	private String cacheKey;
	
	
	public Method getMethod() {
		return method;
	}
	public void setMethod(Method method) {
		this.method = method;
	}
	
	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}

	public String getMethodName() {
		return methodName;
	}
	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}
	
	public Object getBeanObject() {
		return beanObject;
	}
	
	
	public EngineAppMethodBean(String cacheKey,Class<?> beanClass,Annotation annotation, String beanName,Object beanObject,String methodName,
			String version,String describe, Method method,Type[] parameterTypes,Class<?>[] parameterClass,Class<?> returnType) {
		super();
		this.cacheKey = cacheKey;
		this.methodName = methodName;
		this.beanClass = beanClass;
		this.beanObject = beanObject;
		if(!Proxy.isProxyClass(annotation.getClass())){
			this.annotationClass = annotation.getClass();
		}else{
			this.annotationClass = annotation.annotationType();
		}
		this.annotationAttributes =  AnnotationUtils.getAnnotationAttributes(annotation);
		this.parameterClass = parameterClass;
		this.version = version;
		this.method = method;
		this.beanName = beanName;
		this.parameterTypes = parameterTypes;
		this.returnType = returnType;
		this.describe = describe;
		this.classLoader = Thread.currentThread().getContextClassLoader();
	}

	public Class<?>[] getParameterClass() {
		return parameterClass;
	}
	public void setParameterClass(Class<?>[] parameterClass) {
		this.parameterClass = parameterClass;
	}
	@Transient
	public ClassLoader getClassLoader() {
		return classLoader;
	}

	public String getDescribe(){
		return this.describe;
	}
	public Class<?> getBeanClass() {
		return beanClass;
	}
	public void setBeanClass(Class<?> beanClass) {
		this.beanClass = beanClass;
	}
	public String getBeanName() {
		return beanName;
	}
	public void setBeanName(String beanName) {
		this.beanName = beanName;
	}
	public Type[] getParameterTypes() {
		return parameterTypes;
	}
	public void setParameterTypes(Type[] parameterTypes) {
		this.parameterTypes = parameterTypes;
	}
	public Class<?> getReturnType() {
		return returnType;
	}
	public void setReturnType(Class<?> returnType) {
		this.returnType = returnType;
	}

	public Map<String, Object> getAnnotationAttributes() {
		return annotationAttributes;
	}

	public Class<? extends Annotation> getAnnotationClass() {
		return annotationClass;
	}

	public String getCacheKey() {
		return cacheKey;
	}


}
